home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-25 | 4.8 KB | 201 lines | [TEXT/CWIE] |
- // ==================================================
- // UMacOSTools.cp
- // Copyright (C) 1997 Mizutori Tetsuya
- // March 24, 1997, April 9, 1997.
- // ==================================================
- // All documents are pretty-printed in 10-point Geneva font.
-
- #include <Finder.h>
- #include <UKeyFilters.h>
-
- #include "UMacOSTools.h"
-
-
- // ==================================================
- // • Constructors
- // ==================================================
-
- // --------------------------------------------------
- // • UMacOSTools
- // --------------------------------------------------
-
- UMacOSTools::UMacOSTools()
- {
- }
-
-
- // --------------------------------------------------
- // • UMacOSTools
- // --------------------------------------------------
-
- UMacOSTools::~UMacOSTools()
- {
- }
-
-
- // ==================================================
- // • Member functions (keyboard status)
- // ==================================================
-
- // --------------------------------------------------
- // • IsCommandPeriod
- // --------------------------------------------------
- // Check keyboard status wheather cmd-period is pressed.
-
- Boolean
- UMacOSTools::IsCommandPeriod( void )
- {
- Boolean result = false;
-
- Boolean gotEvent;
- EventRecord theMacOSEvent;
- // gotEvent = ::EventAvail( everyEvent, &theMacOSEvent );
- gotEvent = ::EventAvail( keyDownMask, &theMacOSEvent );
-
- if ( gotEvent && UKeyFilters::IsCmdPeriod( theMacOSEvent ) ) {
- // ::FlushEvents( everyEvent, 0 );
- // ::FlushEvents( keyDownMask, 0 );
- ::WaitNextEvent( keyDownMask, &theMacOSEvent, 0, NULL );
- result = true;
- }
-
- return result;
- }
-
-
-
- // --------------------------------------------------
- // • IsModifierKeyPressed
- // --------------------------------------------------
- // Check keyboard status wheather a modifier key is pressed.
- // cmdKey = 0x0100
- // shiftKey = 0x0200
- // alphaLock = 0x0400
- // optionKey = 0x0800
- // controlKey = 0x1000
-
- Boolean
- UMacOSTools::IsModifierKeyPressed(
- Uint32 inModifierKey )
- {
- EventRecord theMacOSEvent;
- Boolean gotEvent = ::EventAvail( everyEvent, &theMacOSEvent );
-
- return IsModifierKeyPressed( theMacOSEvent, inModifierKey );
- }
-
-
- Boolean
- UMacOSTools::IsModifierKeyPressed(
- const EventRecord & inMacOSEvent,
- Uint32 inModifierKey )
- {
- return ( (inMacOSEvent.modifiers & inModifierKey) != 0 );
- }
-
-
- // ==================================================
- // • Member functions (4-char code string)
- // ==================================================
-
- // --------------------------------------------------
- // • FourCharCodeToPStr
- // --------------------------------------------------
- // Convert a four character code to a Pascal string and return a pointer to the string.
-
- StringPtr
- UMacOSTools::FourCharCodeToPStr(
- FourCharCode inCode,
- StringPtr outString )
- {
- outString[0] = sizeof( FourCharCode );
- for ( long i = 1; i <= outString[0]; i++ ) outString[i] = ' ';
-
- ::BlockMoveData( &inCode, &outString[1], outString[0] );
-
- return outString;
- }
-
-
- // --------------------------------------------------
- // • PStrToFourCharCode
- // --------------------------------------------------
- // Convert an Pascal string to a four character code.
-
- void
- UMacOSTools::PStrToFourCharCode(
- ConstStringPtr inString,
- FourCharCode & outCode )
- {
- outCode = ' '; // 4 white spaces
-
- long len = ( inString[0] < sizeof(OSType) ? inString[0] : sizeof(OSType) );
-
- ::BlockMoveData( &inString[1], &outCode, len );
- }
-
-
- // ==================================================
- // • Member functions (Finder flags)
- // ==================================================
-
- #ifdef COMMENT // Finder Flags
- kIsOnDesk = 0x1,
- kColor = 0xE,
- kIsShared = 0x40,
- kHasBeenInited = 0x100,
- kHasCustomIcon = 0x400,
- kIsStationary = 0x800,
- kNameLocked = 0x1000,
- kHasBundle = 0x2000,
- kIsInvisible = 0x4000,
- kIsAlias = 0x8000,
- #endif // COMMENT
-
- // --------------------------------------------------
- // • SetFinderFlag
- // --------------------------------------------------
- // Set a Finder flag.
-
- void
- UMacOSTools::SetFinderFlag(
- FSSpec & ioMacFSSpec,
- Uint16 inFinderFlag,
- Boolean inSetting )
- {
- FInfo theFinderInfo;
- OSErr err;
- err = ::FSpGetFInfo( &ioMacFSSpec, &theFinderInfo );
- if ( err != noErr ) return;
-
- if ( inSetting ) {
- theFinderInfo.fdFlags |= inFinderFlag;
- } else {
- theFinderInfo.fdFlags &= ~inFinderFlag;
- }
-
- err = ::FSpSetFInfo( &ioMacFSSpec, &theFinderInfo );
- }
-
-
- // --------------------------------------------------
- // • HasFinderFlag
- // --------------------------------------------------
- // Return whether a Finder flag is on or off
-
- Boolean
- UMacOSTools::HasFinderFlag(
- FSSpec & inMacFSSpec,
- Uint16 inFinderFlag )
- {
- FInfo theFinderInfo;
- OSErr err;
- err = ::FSpGetFInfo( &inMacFSSpec, &theFinderInfo );
- if ( err != noErr ) return false;
-
- return ((theFinderInfo.fdFlags & inFinderFlag) == inFinderFlag);
- }
-
-
- // end of program
-